

$(document).ready(function () {
    init( callback, 1,"");
});


function init( callback, current,status) {
    $("#thislist").html("");
    $.ajax({
        type: "post",
        url: urlcore + "/api/withdrawals/selectWithdrawalsList?current="+current+"&status="+status,
        dataType: "json",
        headers: {"Content-Type": "application/json;charset=UTF-8"},
        data: {},
        success: function (data) {//data是返回的hash,key之类的值，key是定义的文件名
            if (data.success == true) {
                callback(data.data.records);
                $('#thiscount').text(data.data.total);
                $("#pager").pager({
                    pagenumber: current,
                    pagecount: data.data.pages,
                    totalcount: data.data.total,
                    buttonClickCallback: PageClick
                });
            } else if (data.code == 'OVERTIME') {
                var thisUrl = window.location.href;
                if (thisUrl.indexOf('login.html') <= -1) {
                    top.window.location.href = "login.html";
                }
            } else {
                alert(data.msg);
            }
        },
        error: function () {
            alert("失败");
        }
    });

}


/*//回调函数
PageClick = function (pageclickednumber) {
    var type = getvl("goodsType") == "" ? 0 : getvl("goodsType");
    init(type, callback, pageclickednumber);
}*/
//回调函数
PageClick = function (pageclickednumber) {
	
    init( callback,pageclickednumber,);
}

var callback = function (data) {
    var html = "", realName = "", status = "",str="",gmtDatetime="",uptDatetime="",agreeDatetime="";
    for (var i = 0; i < data.length; i++) {
        id = data[i].id;
        status= data[i].status;
        if(status==1){
        	str="申请中";
        }else if(status==2){
        	str="已通过";
        }else if(status==3){
        	str="已拒绝";
        }else if(status==4){
        	str="已打款";
        }
        gmtDatetime = data[i].gmtDatetime != null ? new Date(data[i].gmtDatetime).pattern("yyyy-MM-dd hh:mm:ss") : "";
        agreeDatetime=data[i].agreeDatetime != null ? new Date(data[i].agreeDatetime).pattern("yyyy-MM-dd hh:mm:ss") : "";
        uptDatetime=data[i].uptDatetime != null ? new Date(data[i].uptDatetime).pattern("yyyy-MM-dd hh:mm:ss") : "";
        html += "  <tr id=\"" + id + "\">\n" +
            "<td>" + (i + 1) + "</td>\n" +
            "<td>" + data[i].muser.realName+ "</td>\n" +
            " <td>" + data[i].alipayNo + "</td>\n" +
            " <td>" + data[i].money + "</td>\n" +
    		" <td>" + data[i].muser.phone + "</td>\n" +
    		" <td>" + str + "</td>\n" +
    		" <td>" + gmtDatetime + "</td>\n" +
    		" <td>" + agreeDatetime + "</td>\n" +
    		" <td>" + uptDatetime + "</td>\n" ;
    		if(status==1){
			    html+=	"  \t\t<td>\n"+
			            " <a class=\"btn btn-success btn-xs\" href=\"javascript:;\" onclick=\"agreeWithDrawals("+id+",2)\">同意</a>\n" +
			            " <a class=\"btn btn-danger btn-xs\" href=\"javascript:;\" onclick=\"agreeWithDrawals(" + id + ",3)\"> 拒绝</a>\n" +
			            " </td>\n" +
			            " </tr>";
    		}else if(status==2){
    			  html+="  \t\t<td>\n" +
			            " <a class=\"btn btn-success btn-xs\" href=\"javascript:;\" onclick=\"agreeWithDrawals("+id+",4)\">打款</a>\n" +
			           /* " <a class=\"btn btn-danger btn-xs\" href=\"javascript:;\" onclick=\"agreeWithDrawals(" + id + ",3)\"> 拒绝</a>\n" +*/
			            " </td>\n" +
			            " </tr>";
    		}else if(status==3){
    			 html+="  \t\t<td>\n" +
			            " <label class=\"btn  btn-xs\" href=\"javascript:;\" >已拒绝</label>\n" +
			            " </td>\n" +
			            " </tr>";
    		}else if(status==4){
    			 html+="  \t\t<td>\n" +
			            " <label class=\"btn  btn-xs\" href=\"javascript:;\" >已打款</label>\n" +
			            " </td>\n" +
			            " </tr>";
    		}
    		
    }
    $("#thislist").append(html);
}



/**
 * 改变订单状态
 * @param {Object} id
 * @param {Object} type
 */
function agreeWithDrawals(id,type) {
    $.ajax({
        url: urlcore + "/api/withdrawals/agreeWithDrawals?id=" + id+"&type="+type,
        type: "get",
        dataType: "json",
        headers: {"Content-Type": "application/json;charset=UTF-8"},
        success: function (data) {
        	if(data.success==true){
        		location.reload();
        	}else{
        		alert(data.msg)
        	}
            
        },
        error: function (data) {
            alert(data.msg);
        }
    })
}





//搜索
function searchuser() {
    var type = $('#goods_type option:selected').val();//选中的值
    init(type, callback, 1);
}





